#ifndef	__BFX_REFDECODER_H__
#define	__BFX_REFDECODER_H__

namespace BFX
{

class REFEncoding;
#ifdef	BFX_DLL_BUILD
template class BFX_API REF<REFEncoding>;
template class BFX_API REF<REFDecoderFallbackBuffer>;
#endif	//	_USRDLL

// Represents a decoder to converts a sequence of encoded bytes into a set of characters.
class BFX_API REFDecoder : public REFObject
{
public:
	// Initializes a new instance of the decoder class.
	REFDecoder(const REFEncoding* pEncoding);
	virtual ~REFDecoder();

	virtual void Reset();

	// Calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.
	int GetCharCount(const BYTE* pBytes, int nCount, bool bFlush = false);
	// a sequence of bytes starting at the specified byte pointer and any bytes in the internal buffer into a set of characters
	// that are stored starting at the specified character pointer.
	int GetChars(const BYTE* pBytes, int nByteCount, OUT UCHAR* pChars, int nCharCount, bool bFlush = false);

	// Gets a fallback buffer object for the current decoder object, or create a instance if not exists.
	REFDecoderFallbackBuffer* GetFallbackBuffer();
	// Determine whether the fallback buffer exists or not.
	bool HasFallbackBuffer() const
	{
		return (m_pFallbackBuffer != NULL);
	}
	// Indicates the decoder's flush pending status.
	bool IsFlushRequired() const
	{
		return m_bFlushRequired;
	}
	// Clear the decoder's flush pending status.
	void ClearFlushRequired()
	{
		m_bFlushRequired = false;
	}

protected:
	REF<REFDecoderFallbackBuffer>	m_pFallbackBuffer;
	REF<REFEncoding>	m_pEncoding;
	bool	m_bFlushRequired;
};

}	//	namespace BFX

#endif	//	__BFX_REFDECODER_H__
